package com.handong.handserialprogram.module.setVoice;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import com.handong.handserialprogram.R;
import com.handong.handserialprogram.module.setting.SettingActivity;
import com.handong.handserialprogram.module.tasklist.TaskListActivity;
import com.handong.handserialprogram.utils.EventBusUtil;
import com.handong.handserialprogram.utils.SPUtil;


public class SetVoiceActivity extends FragmentActivity implements View.OnClickListener{

    private RadioButton bj1,bj2,bj3,mes1,mes2;
    private RadioGroup bjRadioGroup,mesRadioGroup;
    private TextView headerCenterTitle, mBtnStarDownload;
    private int mesVoice,bjVoice;


    private Context mContext;

    private ImageView headerImage;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_set_voice);
        mContext=SetVoiceActivity.this;
        initUI();
        initData();
    }


    private void initUI() {
        bjRadioGroup = findViewById(R.id.bjRadioGroup);
        mesRadioGroup = findViewById(R.id.mesRadioGroup);
        bj1 = findViewById(R.id.radioButton_bj1);
        bj2 = findViewById(R.id.radioButton_bj2);
        bj3 = findViewById(R.id.radioButton_bj3);
        mes1 = findViewById(R.id.radioButton_mes1);
        mes2 = findViewById(R.id.radioButton_mes2);

        mBtnStarDownload = findViewById(R.id.headerOptionItem);
        mBtnStarDownload.setOnClickListener(this);
        headerCenterTitle = findViewById(R.id.headerCenterTitle);
        headerImage=findViewById(R.id.headerBackLayoutIcon);
        headerImage.setImageResource(R.drawable.ic_menu_back_144);
        findViewById(R.id.headerBackLayout).setOnClickListener(this);

    }

    private void initData() {
        headerCenterTitle.setText("脚环提示音设置");
        mBtnStarDownload.setVisibility(View.VISIBLE);
        findViewById(R.id.headerOptionLayout).setVisibility(View.VISIBLE);
        mBtnStarDownload.setText("确定");
        mesRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {

            }
        });
        chooseRadioGroup();
    }

    private void chooseRadioGroup() {
        int mes_data = SPUtil.getIntValue(SPUtil.TS_NUM);
        if (mes_data==1){
            mes1.setChecked(true);
        }
        if (mes_data==2){
            mes2.setChecked(true);
        }
        int bj_data = SPUtil.getIntValue(SPUtil.BJ_NUM);
        if (bj_data==1){
            bj1.setChecked(true);
        }
        if (bj_data==2){
            bj2.setChecked(true);
        }
        if (bj_data==3){
            bj3.setChecked(true);
        }
    }

    @Override
    public void onClick(View v) {

        switch (v.getId()) {
            case R.id.headerOptionItem:
                pushMes();
                Intent intent = new Intent(mContext, SettingActivity.class);
                startActivity(intent);
                finish();
                break;
            case R.id.headerBackLayout:
                onBackPressed();
                break;
        }
    }

    private void pushMes() {
        if (bj1.isChecked()) {
            bjVoice=1;
        }
        if (bj2.isChecked()) {
            bjVoice=2;
        }
        if (bj3.isChecked()){
            bjVoice=3;
        }

        if (mes1.isChecked()) {
           mesVoice=1;
        }
        if (mes2.isChecked()) {
            mesVoice=2;
        }

        SPUtil.putIntValue(SPUtil.TS_NUM, mesVoice);
        SPUtil.putIntValue(SPUtil.BJ_NUM, bjVoice);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBusUtil.unRegister(this);
    }

}